<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="<?php echo __PUBLIC__?>/Admin/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="<?php echo __PUBLIC__?>/uploadify/uploadify.css" />
	<script type="text/javascript" src='<?php echo __PUBLIC__?>/jquery-1.8.2.min.js'></script>
	<script type="text/javascript" src='<?php echo __PUBLIC__?>/uploadify/jquery.uploadify.min.js'></script>
	<!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
	</style> 
	<script type="text/javascript">
        $(function() {
            $('#file').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
                'uploader' : '<?php echo U('upload')?>',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 1,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='gimg' value='"+data.path+"'/></li>";
                    $("#uploadList ul").prepend(li);
                }
            });
        });
    </script>

    <script type="text/javascript">
        $(function() {
            $('#file1').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
                'uploader' : '<?php echo U('upload')?>',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 1,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='pic' value='"+data.path+"'/></li>";
                    $("#uploadList1 ul").prepend(li);
                }
            });
        });
    </script>

    	<script type="text/javascript">
		$(function(){
			$('[name=cate_cid]').change(function(){
				var tid = $('option:selected').attr('tid');
				var hiddens='<input type="hidden" name="type_tid" value="'+tid+'" />';
				$.ajax({
					type:"post",
					url:"<?php echo U('getTypeAttr')?>",
					data:{id : tid},
					dataType:'json',
					success:function(phpData){
						//规格(可选)
						var spec = '';
						//属性（不可选）
						var attr = '';
						$.each(phpData, function(k,v) {    
							//规格
							if(v.class == 1){
								spec += '<tr class="info">' +
								'<td>'+v.taname+'</td>' +
								'<td>' +
									'<select name="spec['+v.taid+'][value][]" id=""><option value="">请选择</option>';
										$.each(v.tavalue, function(kk,vv) {    
											 spec += '<option value="'+vv+'">'+vv+'</option>';                                                      
										});
									spec += '</select></td><td>附加价格：<input type="text" name="spec['+v.taid+'][price][]" id="" /></td>' +
										'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
							
							}else{//属性
								attr += '<tr class="info">' + 
											'<td>'+v.taname+'</td>' + 
											'<td>' + 
											'<select name="attr['+v.taid+']" id=""><option value="">请选择</option>';
												
												$.each(v.tavalue, function(kk,vv) {    
													 attr += '<option value="'+vv+'">'+vv+'</option>';                                                      
												});
												
								attr += '</select></td></tr>';
							}                                                          
						});
						
						//插入属性
						$('#attr').html(attr);
						$('#spec').html(spec);
						$('#hiddens').html(hiddens);
					}
				});
			})
	
	
			//点击添加规格
			$('.add-spec').live('click',function(){
				//找到父级的tr
				var parentsTr = $(this).parents('tr');
				//把父级的tr克隆复制
				var cloneTr = parentsTr.clone();
				cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
				//插入下一行
				parentsTr.after(cloneTr);
			})
			//删除规格
			$('.remove-spec').live('click',function(){
				$(this).parents('tr').remove();
			})
		})
	</script>
</head>
<body>
	<div class="container-fluid" style="float: ;">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post'>
	<div id="hiddens"></div>
		<fieldset>
			<legend>修改商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="cate_cid">
								<option value="0">-请选择-</option>
								<?php foreach ($cate as $v){?>
									<option value="<?php echo $v['cid']?>" tid='<?php echo $v['type_tid']?>' <?php if($oldData['cate_cid'] == $v['pid']){?>
                 selected="" 
               <?php }?>><?php echo $v['_name']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_bid">
								<option value="0">-请选择-</option>
								
									<?php foreach ($brand as $v){?>
									<option value="<?php echo $v['bid']?>" <?php if($oldData['brand_bid'] == $v['bid']){?>
                selected
               <?php }?>><?php echo $v['bname']?></option>
									<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="<?php echo $oldData['gname']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='gunit' value="<?php echo $oldData['gunit']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='gmarket' value="<?php echo $oldData['gmarket']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='garket' value="<?php echo $oldData['garket']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>商品总库存</td>
						<td>
							<input type="text" name='gcount' value="<?php echo $oldData['gcount']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='gclick' value="<?php echo $oldData['gclick']?>" />
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
			
			<tr class="info">
			<td align="right"></td>
			<td>		
			<select name="attr[<?php echo $v['taid']?>]" id="">
			<option value="">请选择</option>
				
				<option value=""></option>
				
					</select>
			</td>
			</tr>
		
				
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
			 <tr class="info">
				<td></td>
				<td>
					<select name="spec['v.taid'][value][]" id=""><option value="">请选择</option>
					  
							<option value="vv"></option>                                                    
						
					</select>
					</td>
					<td>附加价格：<input type="text" name="spec['v.taid'][price][]" id="" /></td>
						'<td><span class="btn btn-success add-spec">增加规格</span> 
				</td>
			</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
				<div lab="uploadFile">
    						<input id="file"  name="gimg" multiple="true">
    						<span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
   							<div class="right" style="float: right;">
   								
   							</div>
   						 <div id="uploadList">
        					<ul>
        			
                  <img src="<?php echo $oldData['gimg']?>" alt="" />
                  <a href="javascript:;" id="close_img">X</a>
       				 </ul>
   			 </div>
	</div>
					</td>
					<td id='pic-list'></td>
				</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>

						<div lab="uploadFile1">
    						<input id="file1"  name="pic" multiple="true">
    						<span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
   							<div class="right1" style="float: right;">
   							<?php foreach ($detailData['pic'] as $v){?>
  									<img src="<?php echo $v?>"/>
   								<?php }?>
   								
   							</div>
   						 <div id="uploadList1">
        					<ul>

       				 </ul>
   			 </div>
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				
			<div class="form-group">
			<label for="exampleInputEmail1">商品详细</label>
			<!--调用百度编辑器-->
			<script id="xq" type="text/plain" style="width:100%;height:500px;" name="gade" value=""></script>
		    <script>
		        var ue = UE.getEditor('xq');
		    </script>
		</div>

			</table>

			<input type="hidden" name='tid' value='0'/>
			<input type="hidden" name='gid' value="<?php echo $_GET['gid']?>"/>

			<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>